package com.meetingshow.meeting.service;

import java.util.ArrayList;
import java.util.List;

import com.meetingshow.common.base.dao.model.QueryStruct;
import com.meetingshow.common.base.service.BaseServiceImp;
import com.meetingshow.common.base.service.model.QueryResults;
import com.meetingshow.meeting.dao.MeetingDAO;
import com.meetingshow.meeting.dao.UserFollowDAO;
import com.meetingshow.meeting.dao.model.MeetingPO;
import com.meetingshow.meeting.dao.model.UserFollowPO;
import com.meetingshow.meeting.service.model.MeetingQueryParas;
import com.meetingshow.meeting.service.util.MeetingQueryParasBuilder;
import com.meetingshow.meeting.service.util.MeetingServiceParas;

/**
 * @author louyi
 *
 */
public class MeetingServiceImp extends BaseServiceImp implements
        IMeetingService {

    private MeetingDAO meetingDAO;
    private UserFollowDAO userFollowDAO;
    
    /**
     * @return the meetingDAO
     */
    public MeetingDAO getMeetingDAO() {
        return meetingDAO;
    }

    /**
     * @param meetingDAO the meetingDAO to set
     */
    public void setMeetingDAO(MeetingDAO meetingDAO) {
        this.meetingDAO = meetingDAO;
    }

    /**
     * @return the userFollowDAO
     */
    public UserFollowDAO getUserFollowDAO() {
        return userFollowDAO;
    }

    /**
     * @param userFollowDAO the userFollowDAO to set
     */
    public void setUserFollowDAO(UserFollowDAO userFollowDAO) {
        this.userFollowDAO = userFollowDAO;
    }

    @Override
    public Integer saveMeeting(MeetingPO meetingPO) throws Exception {
        return getMeetingDAO().saveMeeting(meetingPO);
    }

    @Override
    public void updateMeeting(MeetingPO meetingPO) throws Exception {
        getMeetingDAO().updateMeeting(meetingPO);
    }

    @Override
    public void removeMeeting(MeetingPO meetingPO) throws Exception {
        getMeetingDAO().removeMeeting(meetingPO);
    }
    
    @Override
    public MeetingPO loadMeetingById(Integer meetingId) throws Exception {
        return getMeetingDAO().loadMeetingById(meetingId);
    }

    @Override
    public QueryResults<MeetingPO> queryMeeting(
            MeetingQueryParas meetingQueryParas) throws Exception {
        QueryStruct queryStruct = new QueryStruct();
        List<String> tableList = new ArrayList<String>();
        List<String> returnObjectList = new ArrayList<String>();
        
        tableList.add(MeetingServiceParas.MEETING_PO);
        returnObjectList.add(MeetingServiceParas.MEETING_PO);
        
        queryStruct.setTableList(tableList);
        queryStruct.setReturnObjectList(returnObjectList);
        
        queryStruct = MeetingQueryParasBuilder.meetingQueryBuilder(queryStruct, meetingQueryParas);
        QueryResults<MeetingPO> queryResults = getMeetingDAO().queryMeeting(queryStruct);
        return queryResults;
    }

    @Override
    public int addFollowCount(UserFollowPO userFollowPO) throws Exception {
        getUserFollowDAO().saveUserFollow(userFollowPO);
        return getMeetingDAO().addFollowCount(userFollowPO.getMeeting().getMeetingId());
    }
    
    @Override
    public int subFollowCount(UserFollowPO userFollowPO) throws Exception {
        getUserFollowDAO().removeUserFollow(userFollowPO);
        return getMeetingDAO().subFollowCount(userFollowPO.getMeeting().getMeetingId());
    }
}
